<template>
  <div>
    {{ dateStr }}
    <div></div>
    {{ dateFormat }}
    <div></div>
    {{ dateQua }}季度
    <ul>
      <li
        v-for="(item, index) in getList"
        :key="index"
        style="text-decoration: line-through"
      >
        {{ item.date }}
      </li>
    </ul>
    {{ getList }}
    <!-- <CustomLoading :visible="visible" text="加载中" /> -->
  </div>
</template>

<script>
import { formatDate } from "@/utils/date";
import { Format } from "@/utils/methods";
// import CustomLoading from "@/components/loading/loading";
// import Loading from "@/components/loading/index.js";
export default {
  name: "testjs",
  // components: {
  //   CustomLoading,
  // },
  data() {
    return {
      date: Date.now(),
      list: [
        {
          date: Date.now(),
        },
      ],
      arr:[1,2,3],
     fullscreenLoading: false
    };
  },
  created() {
     this.visible = true
     this.openFullScreen2()
    // fetch(1).then(() => {
    //   this.visible = false
    // })
  },
  computed: {
    dateStr() {
      return formatDate(this.date);
    },
    dateFormat() {
      return Format(this.date, "yyyy-MM-dd HH:mm:ss");
    },
    dateQua() {
      return Format(this.date, "yyyy-MM-dd qq");
    },
    getList() {
      return this.list.map((item) => {
        return {
          // ...item,
          date: formatDate(item.date),
        };
      });
    },
  },
  mounted() {
    this.fn1();
    console.log("-------------------");
    console.log(this.isType(this.arr),this.isType(11));
    this.arraySet()
  },
  methods: {
    fn1() {
      let arr = [
        {
          id: 0,
          pid: -1,
          name: "sadas",
        },
        {
          id: 1,
          pid: -1,
          name: "sadas",
        },
        {
          id: 2,
          pid: -1,
          name: "sadas",
        },
        {
          id: 3,
          pid: -1,
          name: "sadas",
        },
        {
          id: 4,
          pid: 1,
          name: "sadas",
        },
        {
          id: 5,
          pid: 1,
          name: "sadas",
        },
      ];
      let obj = {};
      arr.map((v, i) => {
        if (obj[v.pid]) {
          if (obj[v.pid].children) {
            obj[v.pid].children.push(v);
          } else {
            obj[v.pid].children = [v];
          }
        } else {
          obj[v.pid] = {
            children: [v],
          };
        }

        if (obj[v.id]) {
          v.children = obj[v.id].children;
        }
        obj[v.id] = v;
      });
      console.log(obj[-1]);
      console.log(arr);
    },
    openFullScreen2() {
        const loading = this.$loading({
          lock: true,
          text: '请稍等',
          spinner: 'el-icon-loading',
          background: 'rgba(0, 0, 0, 0.7)'
        });
        setTimeout(() => {
          loading.close();
        }, 2000);
      },
      isType(arr){
        if(typeof arr!=='object') return false
        else return true
      },
      arraySet(){
        let arr=[1,1,2,2]
        let newArr=new Set(arr)
        console.log(Array.from(newArr));
        console.log([...newArr]);
      }
  },
};
</script>

<style lang="scss" scoped>
</style>
